eventObj={
	beforeSave:function(){
		$("select[name='SDdetail_REPORT_ID'] ").each(function(){
			var $option = $(this).children("option:selected");
			$("input[name='SDdetail_report_name']").val($option.text());
		});
		$("select[name='SDdetail_BLOCK_ID']").each(function(){
			var $option = $(this).children("option:selected");
			$("input[name='SDdetail_block_name']").val($option.text());
		});
		$("select[name='SDdetail_x_field_name']").each(function(){
			var $option = $(this).children("option:selected");
			$("input[name='SDdetail_x_display_name']").val($option.text());
		});
		$("select[name='SDdetail_y_field_name']").each(function(){
			var $option = $(this).children("option:selected");
			$("input[name='SDdetail_y_display_name']").val($option.text());
		});
		$("select[name='SDdetail_statics_field_name']").each(function(){
			var $option = $(this).children("option:selected");
			$("input[name='SDdetail_statics_display_name']").val($option.text());
		});
	},
	initForm:function(data){
		var reportId = $("select[name='SDdetail_REPORT_ID']").val();
		loadField(reportId, function(){
			if (data) {
				$("select[name='SDdetail_x_field_name'] option[value="+ data.x_field_name).prop("selected", true);
				$("select[name='SDdetail_y_field_name'] option[value="+ data.y_field_name).prop("selected", true);
				$("select[name='SDdetail_statics_field_name'] option[value="+ data.statics_field_name).prop("selected", true);
			}
		});
		$("select[name='SDdetail_REPORT_ID']").change(function(){
			loadField($(this).val());
		});
		$("select[name='SDdetail_TYPE']").change(function(){
			typeChange($(this).val());
		});
		$("select[name='SDdetail_TYPE']").change();
	}
}

function loadField(reportId, callback){
	$.ajax({
		type: "POST",
		url:baseURL+"/report/commsearch/commsearchlist/loadField.do",
		dataType:'json',
		data:{reportId:reportId},
		success:function(data){
			var html = "<option></option>";
			for(var key in data){
				html += "<option value='"+data[key].fieldName+"'>"+data[key].displayName+"</option>";
			}
			$("select[name='SDdetail_x_field_name']").children("option").remove();
			$("select[name='SDdetail_y_field_name']").children("option").remove();
			$("select[name='SDdetail_statics_field_name']").children("option").remove();
			$("select[name='SDdetail_x_field_name']").append(html);
			$("select[name='SDdetail_y_field_name']").append(html);
			$("select[name='SDdetail_statics_field_name']").append(html);
			if (callback) {
				callback();
			}
		}
	});
}

function typeChange(type) {
	switch(type) {
	case '1': // 列表
	case '5': //自定义
		$('select[name=SDdetail_x_field_name]').parents('tr').hide();
		$('select[name=SDdetail_y_field_name]').parents('tr').hide();
		$('select[name=SDdetail_statics_field_name]').parents('tr').hide();
		$('input[name=SDdetail_y_axis_unit]').parents('tr').hide();
		$('select[name=SDdetail_map_type]').parents('tr').hide();
		break;
	case '2': // 柱图
	case '3': // 折线图
		$('select[name=SDdetail_x_field_name]').parents('tr').find('th').text('X 轴数据');
		$('select[name=SDdetail_y_field_name]').parents('tr').find('th').text('Y 轴数据');
		$('select[name=SDdetail_x_field_name]').parents('tr').show();
		$('select[name=SDdetail_y_field_name]').parents('tr').show();
		$('select[name=SDdetail_statics_field_name]').parents('tr').show();
		$('input[name=SDdetail_y_axis_unit]').parents('tr').show();
		$('select[name=SDdetail_map_type]').parents('tr').hide();
		break;
	case '4': // 饼图
	case '6': // 地图
		$('select[name=SDdetail_statics_field_name]').parents('tr').hide();
		$('input[name=SDdetail_y_axis_unit]').parents('tr').hide();
		$('select[name=SDdetail_x_field_name]').parents('tr').find('th').text('统计类型');
		$('select[name=SDdetail_y_field_name]').parents('tr').find('th').text('统计数据');
		$('select[name=SDdetail_x_field_name]').parents('tr').show();
		$('select[name=SDdetail_y_field_name]').parents('tr').show();
		if (type == 4)
			$('select[name=SDdetail_map_type]').parents('tr').hide();
		else
			$('select[name=SDdetail_map_type]').parents('tr').show();
		break;
	}
}